<?php

/**
 * alltosun.com 查看经销商旗下门店的设备绑定情况
 * ============================================================================
 * 版权所有 (C) 2009-2011 北京互动阳光科技有限公司，并保留所有权利。
 * 网站地址: http://www.alltosun.com
 * ----------------------------------------------------------------------------
 * 许可声明：这是一个开源程序，未经许可不得将本软件的整体或任何部分用于商业用途及再发布。
 * ============================================================================
 * $Author: 高昂 (gaoa@alltosun.com) $
 * $Date: 2016-4-21 下午12:15:18 $
 * $Id: $
 */
class Action
{
    /**
     * 查看经销商旗下门店的设备绑定情况
     */
    public function index() {
        $mobile = Request::getParam('mobile', '');
        $page_no = Request::getParam('page_no', 1);
        $status = Request::getParam('status', -1);

        $store_list = array();
        if (!$mobile) {
            Response::assign('mobile', $mobile);
            Response::assign('store_list', $store_list);
            Response::display('admin/dealer_store_device.html');
            return;
        }

        $dealer_info = user_helper::get_user_info_by_mobile($mobile);
        if ($dealer_info) {
            $filter['agency_id'] = $dealer_info['id'];
            if ($status != -1) {
                $filter['status'] = $status;
            }
            $store_list = get_data_list('store', $filter, 'ORDER BY `id` DESC', $page_no, 100);
            if ($store_list) {
                $type_arr = store_config::$type_arr;
                foreach ($store_list as $k => $v) {
                    $user_info = _uri('user', @$v['owner_id']);
                    if ($user_info) {
                        $store_list[$k]['user_name'] = $user_info['user_name'];
                        $store_list[$k]['mobile'] = $user_info['mobile'];
                    }
                    if (isset($type_arr[$v['type']])) {
                        $store_list[$k]['type_name'] = $type_arr[$v['type']];
                    }
                    if ($v['agency_id']) {
                        $dealer_info = _uri('user', $v['agency_id']);
                        if ($dealer_info) {
                            $store_list[$k]['dealer_name'] = $dealer_info['realname'];
                            $store_list[$k]['dealer_mobile'] = $dealer_info['mobile'];
                        }
                    }

                    // 统计设备绑定关系
                    $device_list = device_helper::get_store_typed_device_by_store_id($v['id']);
                    $store_list[$k]['device_list'] = $device_list;
                }
            }
        }

        Response::assign('mobile', $mobile);
        Response::assign('status', $status);
        Response::assign('store_list', $store_list);
        Response::display('admin/dealer_store_device.html');

    }
}

?>